<!--
 - Author : wang885298.
 - Date   : 2018/7/9.
 - File   : login.登录页
 -->

<template>
  <div class="login">
    <div class="login-con">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>新和兴GIS锚点平台 源数据后台</span>
        </div>
        <el-form :model="ruleLogin" status-icon :rules="rules" ref="ruleLogin" label-width="100px"
            class="demo-ruleForm">
          <el-form-item label="用户名" prop="userName">
            <el-input type="text" v-model="ruleLogin.userName" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="pass">
            <el-input type="password" v-model="ruleLogin.pass" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="验证码" prop="code">
            <el-col :span="16">
              <el-input type="text" v-model="ruleLogin.code" auto-complete="off"></el-input>
            </el-col>
            <el-col :span="8" style="text-align: right">
              <el-button type="primary">验证码</el-button>
            </el-col>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleLogin')">提交</el-button>
            <el-button @click="resetForm('ruleLogin')">重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>

    </div>
  </div>
</template>

<script>
export default {
  data () {
    let validateUserName = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入用户名'))
      } else {
        callback()
      }
    }
    let validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'))
      } else {
        callback()
      }
    }
    let validateCode = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入验证码'))
      } else {
        callback()
      }
    }
    return {
      ruleLogin: {
        userName: '',
        pass: '',
        code: ''
      },
      rules: {
        userName: [
          { validator: validateUserName, trigger: 'blur' }
        ],
        pass: [
          { validator: validatePass, trigger: 'blur' }
        ],
        code: [
          { validator: validateCode, trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style lang="less">
  .login {
    width: 100%;
    height: 100%;
    background-image: url('../assets/images/login_bg.jpg');
    background-size: cover;
    background-position: center;
    position: relative;
  }
  .login-con {
    position: absolute;
    right: 160px;
    top: 50%;
    -webkit-transform: translateY(-60%);
    transform: translateY(-60%);
    width: 30%;
    max-width: 480px;
    min-width: 400px;
  }
</style>
